<?php

namespace ticket\modules\frontend\models;

use Yii;

/**
 * This is the model class for table "tk_category_info".
 *
 * @property int $id
 * @property int $cat_id
 * @property string $cat_name
 * @property string $albums_image
 * @property int $score 1-5
 * @property int $buyer
 * @property string $opening_hours 开园时间
 * @property string $scenic_address 景点地址
 * @property string $scenic_introduce 景点介绍
 * @property string $label
 * @property int $floor_price
 * @property string $update_time
 */
class CategoryInfo extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'tk_category_info';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['cat_id'], 'required'],
            [['cat_id', 'score', 'buyer', 'floor_price'], 'integer'],
            [['scenic_introduce'], 'string'],
            [['update_time'], 'safe'],
            [['cat_name'], 'string', 'max' => 64],
            [['albums_image'], 'string', 'max' => 1024],
            [['opening_hours', 'scenic_address'], 'string', 'max' => 255],
            [['label'], 'string', 'max' => 512],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'cat_id' => 'Cat ID',
            'cat_name' => 'Cat Name',
            'albums_image' => 'Albums Image',
            'score' => 'Score',
            'buyer' => 'Buyer',
            'opening_hours' => 'Opening Hours',
            'scenic_address' => 'Scenic Address',
            'scenic_introduce' => 'Scenic Introduce',
            'label' => 'Label',
            'floor_price' => 'Floor Price',
            'update_time' => 'Update Time',
        ];
    }

    public function getInfo($cat_id)
    {
        $info = self::find()->where('cat_id = :cid',[':cid' => $cat_id])->asArray()->one();
        if (!empty($info) and !empty($info['albums_image'])){
            $info['albums_image'] = explode(',',$info['albums_image']);
            $info['video_image'] = $info['albums_image'][0];
        }
        return $info;
    }
}
